import {reqUserAccount, reqUserDetail} from "@/http/api";


export default {
    namespaced: true,//开启命名空间
    state: {
        userinfo: {},
        profile: {}
    },
    mutations: {
        clearInfo (state) {
            state.userinfo = {}
            state.profile = {}
        },
        ACCOUNT(state, result) {
            state.userinfo = result.data.data.profile || {}
        },
        USERINFO(state, result) {
            state.profile = result.data.profile || {}
        }
    },
    actions: {
        async Account({commit}, cookies) {
            const result = await reqUserAccount(cookies);
            if (result.data.data.code == 200) {
                commit('ACCOUNT', result)
                if (result.data.data.profile) {
                    let info = await reqUserDetail(result.data.data.profile.userId)
                    commit('USERINFO', info)
                }
            } else {
                return new Promise(reject => {
                    reject('fail')
                })
            }
        }
    },
    getters: {},
    plugins: []
}
